import {  trackDetail ,queryDrivingSumary ,queryOverspeedSumary ,queryDrivingDetailPage ,findWarningPageList ,findChangeRecord ,queryOverspeedDetailPage} from '@/api/list'
export default {
  data(){
    return {
      trakcerId:'',
      showdetails: false,
      devicerow: {},
      driverow: {},
      overspeedrow: {},
      loading:true,
      driving: {
        detailList: [],
        detailsCount: 0
      },
      overspeed: {
        overspeedList: [],
        overspeedCount: 0
      },
      warning:{
        warningList :[],
        warningCount:0
      },
      ChangeRecord:{
        ChangeRecordList:[],
        ChangeRecordCount:0
      },
      drivingquery:{
        pageSize: 5,
        currentPage: 1
      }
    }
  },
  methods: {
    trakerDetail(trackerId,drivingquery){
      this.getdeviedetail(trackerId)
      this.getDriving(trackerId)
      this.getspeed(trackerId)
      this.getDrivinglist(trackerId,drivingquery)
      this.getspeedlist(trackerId,drivingquery)
      this.getwarninlist(trackerId,drivingquery)
      this.getrecordlist(trackerId,drivingquery)
    },
    getdeviedetail(trackerId){
      this.loading = true
      trackDetail({trackerId:trackerId}).then(response => {
        if(response && response.body){
          this.devicerow=response.body
        }else {
          this.devicerow={}
        }
        this.loading = false
      })
    },
    getDriving(trackerId){
      this.loading = true
      queryDrivingSumary({trackerId:trackerId}).then(response => {
        if(response && response.body){
          this.driverow=response.body
        }else {
          this.driverow={}
        }
        this.loading = false
      })
    },
    getspeed(trackerId){
      this.loading = true
      queryOverspeedSumary({trackerId:trackerId}).then(response => {
        if(response && response.body){
          this.overspeedrow=response.body
        }else {
          this.overspeedrow={}
        }
        this.loading = false
      })
    },
    getDrivinglist(trackerId,drivingquery){
      this.loading = true
      queryDrivingDetailPage({trackerId:trackerId,...drivingquery}).then(response => {
        if(response && response.body){
          this.driving.detailList= response.body.detailList
          this.driving.detailsCount=response.body.count
        }else {
          this.driving.detailList= []
          this.driving.detailsCount=0
        }
        this.loading = false
      })
    },
    getspeedlist(trackerId,drivingquery){
      this.loading = true
      queryOverspeedDetailPage({trackerId:trackerId,...drivingquery}).then(response => {
        if(response && response.body){
          let body = JSON.parse(JSON.stringify(response.body.overspeedDetailList));
          this.warning.warningList = body
          this.warning.warningCount = response.body.count
        }else {
          this.overspeed.overspeedList=[]
          this.overspeed.overspeedCount= 0
        }
        this.loading = false
      })
    },
    getwarninlist(trackerId,drivingquery){
      this.loading = true
      findWarningPageList({trackerId:trackerId,...drivingquery}).then(response => {
        if(response && response.body){
          this.warning.warningList=response.body.trackerWarningResponseList
          this.warning.warningCount = response.body.count
        }else {
          this.warning.warningList=[]
          this.warning.warningCount=0
        }
        this.loading = false
      })
    },
    getrecordlist(trackerId,drivingquery){
      this.loading = true
      findChangeRecord({trackerId:trackerId,...drivingquery}).then(response => {
        if(response && response.body){
          this.ChangeRecord.ChangeRecordList= response.body.changeRecordList
          this.ChangeRecord.ChangeRecordCount= response.body.count
        }else {
          this.ChangeRecord.ChangeRecordList= []
          this.ChangeRecord.ChangeRecordCount=0
        }
        this.loading = false
      })
    },
    changeModalPage({tabs,val}){
      let newquery={
        pageSize: 5,
        currentPage: val,
      }

      if(tabs==1){
        this.getDrivinglist(this.trakcerId,newquery)
      }else if(tabs==2){
        this.getspeedlist(this.trakcerId,newquery)
      }else if(tabs==3){
        this.getwarninlist(this.trakcerId,newquery)
      }else {
        this.getrecordlist(this.trakcerId,newquery)
      }
    }
  }
}
